package com.czy.owner.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.ShoppingModel;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;

/**
 * Created by asus on 2017/9/27.
 */
public class HomeActivityZoneAdapter extends RecyclerArrayAdapter<ShoppingModel.ActivityZoneListBean> {
    private Context context;

    private Integer[] colorsLib = {Color.rgb(0xff, 0x5a, 0x02), Color.rgb(0x14, 0xdb, 0xf4), Color.rgb(0x9c, 0x9a, 0xfc), Color.rgb(0x6d, 0xdc, 0x46)};

    public HomeActivityZoneAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new HomeActivityZoneAdapter.HomeActivityZoneViewHolder(parent);
    }

    class HomeActivityZoneViewHolder extends BaseViewHolder<ShoppingModel.ActivityZoneListBean> {
        private ImageView ivZoneImg;
        private TextView tvZoneTite;
        private TextView tvZoneDescrtion;


        public HomeActivityZoneViewHolder(ViewGroup parent) {
            super(parent, R.layout.item_home_zone_recycler);
            ivZoneImg = $(R.id.iv_zone_img);
            tvZoneTite = $(R.id.tv_zone_title);
            tvZoneDescrtion = $(R.id.tv_zone_descrtion);
        }

        @Override
        public void setData(ShoppingModel.ActivityZoneListBean model) {
            super.setData(model);
            GlideUtils.loadImage(context, model.getLogo(), ivZoneImg, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.default_icon, R.mipmap.default_icon);

            tvZoneTite.setTextColor(colorsLib[getAdapterPosition() % 4]);
            StringBuilder stringBuilder = new StringBuilder();
            if (!TextUtils.isEmpty(model.getTitle()) && model.getTitle().length() > 6) {
                stringBuilder.append(model.getTitle().substring(0, 5) + "...");

            } else {
                stringBuilder.append(model.getTitle());
            }
            tvZoneTite.setText(stringBuilder + "");
            tvZoneDescrtion.setText(model.getDescription1());
        }
    }
}

